
import UIKit
import SnapKit
import SwiftEventBus


class ChatMessageCell : UITableViewCell{
    
    var history: History!
    func bindViewModel(_ history: History) {
        
        nameLabel.text = history.keyword
//        descriptionLabel.text = history.description
        
        let attributedString = NSMutableAttributedString(string: history.answer ?? "")
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 3 // Whatever line spacing you want in points
        attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value:paragraphStyle, range:NSMakeRange(0, attributedString.length))
        descriptionLabel.attributedText = attributedString
        
    }
    
    var useButton: UIButton = {
        let copyButton = UIButton(type: .custom)
        copyButton.setTitle("复制答案", for: .normal)
        copyButton.layer.cornerRadius = 16
        copyButton.setTitleColor(.primaryColor, for: .normal)
        copyButton.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .semibold)
        copyButton.layer.borderColor = (UIColor.primaryColor).cgColor
        copyButton.layer.borderWidth = 1
        copyButton.isUserInteractionEnabled = false
//        copyButton.addTarget(self, action: #selector(handleCopyButtonTapped(_:)), for: .touchUpInside)
        return copyButton
    }()
    
    
    
    
    
    var nameLabel: UILabel = {
        let titelLabel = UILabel()
        titelLabel.font = UIFont.boldSystemFont(ofSize: 17)
        titelLabel.textColor = .primaryColor
        titelLabel.text = "学习顾问"
        titelLabel.numberOfLines = 1
        return titelLabel
    }()
    
    var descriptionLabel: UILabel = {
        let titelLabel = UILabel()
        titelLabel.font = UIFont.systemFont(ofSize: 15)
        titelLabel.textColor = .white
    
        titelLabel.text = "学习顾问"
        titelLabel.numberOfLines = 6
        
        
        
        return titelLabel
    }()
    
    
    
    
    
    @objc private func handleCopyButtonTapped(_ sender: Any) {
        SwiftEventBus.post(EVENT_NAME_SELECT_ROLE, sender: history)
        
    }
    
    @objc private func handleRightBarButtonTapped(_ sender: Any) {
        
    }
    
    @objc func chatTapped(tapGestureRecognizer: UITapGestureRecognizer)
    {
        //        delegate?.didTapChat(user: user)
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.addSubview(nameLabel)
        self.addSubview(descriptionLabel)
        self.addSubview(useButton)
        self.backgroundColor = primaryDarkBackgroundColor
        
        
        
        
        
        nameLabel.snp.makeConstraints { make in
            make.top.equalTo(self).offset(12)
            make.left.equalTo(self).offset(12)
            make.right.equalTo(self).offset(-12)
            
        }
        
        descriptionLabel.snp.makeConstraints { make in
            make.top.equalTo(nameLabel.snp.bottom).offset(12)
            make.left.equalTo(self).offset(12)
            make.right.equalTo(self).offset(-12)
            
        }
        
        useButton.snp.makeConstraints({ make in
            make.centerX.equalTo(self)
            make.bottom.equalTo(self.snp.bottom).offset(-12)
            make.width.equalTo(90)
            make.height.equalTo(32)
        })
        
    }
    
    
    
    
    
}

